const fs = require("fs")
const User = require("./controller/User")
const lib = fs.readdirSync(__dirname + "/model")
var models = {}
for (let item of lib) {
  let model = item.replace(".js", "")
  models[model] = require("./model/" + item)
}

const association = async () => {
  try {
  models.File.belongsTo(models.User,{
    as: 'user', foreignKey: 'userId' 
  })
  models.File.belongsTo(models.User,{
    as: 'occupyUser', foreignKey: 'occupyUserId' 
  })
  models.User.hasMany(models.File)
  const db = require('./database')
  await db.sync({ alter: true });
  }
  catch(error){
    console.log(error)
  }
}
module.exports = association
